#include <iostream>
#include <memory>

using std::cout;

class Info {
public:
  Info() : nref(1)
  {
    cout << "Constructor of Info\n";
  }

  void put()
  {
    if (--nref == 0) {
      delete this;
    }
  }

  ~Info()
  {
    cout << "Desctructor of Info\n";
  }

private:
  int nref;
};

class Test {
  std::unique_ptr<Info, std::function<void(Info*)> > info_deleter;
public:
  Test(Info *info) :
    info_deleter{info, [](Info *p){ p->put();} }
  {
    cout << "Constructor of Test\n";
  }
  ~Test()
  {
    cout << "Desctructor of Test\n";
  }
};

int main(int argc, char *argvp[])
{
  Info *info = new Info;
  Test *t = new Test(info);
  delete t;

  return 0;
}
